package com.example.musicplayer.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

import com.example.musicplayer.provider.MusicAndMusicListProvider;
import com.example.musicplayer.provider.MusicListProvider;

public class DbHelper extends SQLiteOpenHelper {

    private String dbTable; // 数据表名称

    public DbHelper(@Nullable Context context,
                    @Nullable String name,
                    @Nullable SQLiteDatabase.CursorFactory factory,
                    int version,
                    String dbTable) {
        super(context, name, factory, version);
        this.dbTable = dbTable;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(MusicListProvider.SQL);
        db.execSQL(MusicAndMusicListProvider.SQL);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + dbTable);
        onCreate(db);
    }
}
